/*
 * Equipo creador por Hector Adrian Valdecantos
 * emai: hvaldecantos@gmail.com
 * 30 de Mayo del 2009
 */

package org.javahispano.javacup.tacticas_aceptadas.hector.equipohectorvaldecantos;

import org.javahispano.javacup.modelo.Posicion;

public class Utiles {
	public static double redondeaMultiplo(double valor, double divisor) {
		return Math.round(valor / divisor) * divisor;
	}

	public static double redondear(double valor, double divisor) {
		if (Double.isNaN(valor))
			return valor;
		else
			return Math.round(valor * divisor) / divisor;
	}

	public static double getPendiente(Posicion a, Posicion b) {
		double m, divisor, dividendo;
		try {
			dividendo = (a.getY() - b.getY());
			divisor = (a.getX() - b.getX());

			if (divisor == 0) {
				if (dividendo > 0)
					m = Double.MAX_VALUE;
				else if (dividendo < 0)
					m = -Double.MAX_VALUE;
				else
					m = dividendo / divisor;
			} else
				m = dividendo / divisor;
			return m;
		} catch (IndexOutOfBoundsException e) {
			return 0.0;
		}
	}
}
